/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = '';
  
  checkConfig(config);
  @endpoint = getEndpoint('alicloudproc', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model Address {
  cityCode?: string(name='cityCode'),
  detail?: string(name='detail', example='蒙姑镇XXX'),
  districtCode?: string(name='districtCode'),
  provinceCode?: string(name='provinceCode', example='530000'),
}

model Company {
  name?: string(name='name', example='XXX公司'),
  uscc?: string(name='uscc', example='12150123XX10486121'),
}

model Contact {
  email?: string(name='email', example='XX@XX.XX'),
  name?: string(name='name', example='XXX'),
  phone?: string(name='phone', example='1XXXXXXXXXX'),
}

model ExtendInfo {
  depositAmount?: double(name='depositAmount', example='29990.00'),
  desc?: string(name='desc', example='其他说明事项XXX'),
}

model SubjectExtendInfo {
  deliveryDesc?: string(name='deliveryDesc', example='交货期我方计划为准XXX'),
  desc?: string(name='desc', example='XXX标准XXX要求'),
}

model CreateSourcingProjectRequest {
  address?: {
    cityCode?: string(name='CityCode', example='530600'),
    detail?: string(name='Detail', example='蒙姑镇XXX'),
    districtCode?: string(name='DistrictCode', example='530624'),
    provinceCode?: string(name='ProvinceCode', example='530000'),
  }(name='Address', example='{"provinceCode":"530000","cityCode":"530600","districtCode":"530624","detail":"蒙姑镇XXX"}'),
  bizId?: string(name='BizId', example='XXXIDXXX'),
  bizNo?: string(name='BizNo', example='XXXNOXXX'),
  bizType?: string(name='BizType', example='notice'),
  company?: {
    name?: string(name='Name', example='XXX公司'),
    uscc?: string(name='Uscc', example='12150123XX10486121'),
  }(name='Company', example='{"name":"XXX公司","uscc":"12150123XX10486121"}'),
  contact?: {
    email?: string(name='Email', example='XX@XX.XX'),
    name?: string(name='Name', example='XXX'),
    phone?: string(name='Phone', example='1XXXXXXXXXX'),
  }(name='Contact', example='{"name":"XXX","phone":"1XXXXXXXXXX","email":"XX@XX.XX"}'),
  createTime?: string(name='CreateTime', example='2023-11-08T00:01:59Z'),
  expireTime?: string(name='ExpireTime', example='2023-12-08T00:01:59Z'),
  extendInfo?: map[string]string(name='ExtendInfo', example='{"depositAmount":29990.00,"desc":"其他说明事项XXX"}'),
  sourceUrl?: string(name='SourceUrl', example='https://XXX.XXX.com/XXX'),
  subBizType?: string(name='SubBizType', example='bidding_notice_enquire'),
  subjects?: [ 
    {
      address?: {
        cityCode?: string(name='CityCode', example='530600'),
        detail?: string(name='Detail', example='蒙姑镇XXX'),
        districtCode?: string(name='DistrictCode', example='530624'),
        provinceCode?: string(name='ProvinceCode', example='530000'),
      }(name='Address', example='{"provinceCode":"530000","cityCode":"530600","districtCode":"530624","detail":"蒙姑镇XXX"}'),
      code?: string(name='Code', example='标的编码XXX'),
      extendInfo?: map[string]string(name='ExtendInfo', example='{"deliveryTime":"2023-11-16T00:01:59Z","deliveryDesc":"交货期描述XXX","desc":"XXX标准XXX要求","brand":"XXX品牌"}'),
      name?: string(name='Name', example='标的名称XXX'),
      quantity?: double(name='Quantity', example='888.00'),
      spec?: string(name='Spec', example='规格型号XXX'),
      unit?: string(name='Unit', example='单位XX'),
    }
  ](name='Subjects', example='{"code":"标的编码XXX","name":"标的名称XXX","spec":"规格型号XXX","quantity":"88.00","unit":"单位XX","attachments":[{"fileName":"fileName","url":"https://XXX.XXX-XX-XXX.aliyuncs.com/XXX/XX/XXX.XXX"}],"address":"{\\"provinceCode\\":\\"530000\\",\\"cityCode\\":\\"530600\\",\\"districtCode\\":\\"530624\\",\\"detail\\":\\"蒙姑镇XXX\\"}","extendInfo":"{\\"deliveryTime\\":\\"2023-11-16T00:01:59Z\\",\\"deliveryDesc\\":\\"交货期我方计划为准XXX\\",\\"desc\\":\\"XXX标准XXX要求\\",\\"brand\\":\\"XXX品牌\\"}"}'),
  title?: string(name='Title', example='XX标题'),
}

model CreateSourcingProjectShrinkRequest {
  addressShrink?: string(name='Address', example='{"provinceCode":"530000","cityCode":"530600","districtCode":"530624","detail":"蒙姑镇XXX"}'),
  bizId?: string(name='BizId', example='XXXIDXXX'),
  bizNo?: string(name='BizNo', example='XXXNOXXX'),
  bizType?: string(name='BizType', example='notice'),
  companyShrink?: string(name='Company', example='{"name":"XXX公司","uscc":"12150123XX10486121"}'),
  contactShrink?: string(name='Contact', example='{"name":"XXX","phone":"1XXXXXXXXXX","email":"XX@XX.XX"}'),
  createTime?: string(name='CreateTime', example='2023-11-08T00:01:59Z'),
  expireTime?: string(name='ExpireTime', example='2023-12-08T00:01:59Z'),
  extendInfoShrink?: string(name='ExtendInfo', example='{"depositAmount":29990.00,"desc":"其他说明事项XXX"}'),
  sourceUrl?: string(name='SourceUrl', example='https://XXX.XXX.com/XXX'),
  subBizType?: string(name='SubBizType', example='bidding_notice_enquire'),
  subjectsShrink?: string(name='Subjects', example='{"code":"标的编码XXX","name":"标的名称XXX","spec":"规格型号XXX","quantity":"88.00","unit":"单位XX","attachments":[{"fileName":"fileName","url":"https://XXX.XXX-XX-XXX.aliyuncs.com/XXX/XX/XXX.XXX"}],"address":"{\\"provinceCode\\":\\"530000\\",\\"cityCode\\":\\"530600\\",\\"districtCode\\":\\"530624\\",\\"detail\\":\\"蒙姑镇XXX\\"}","extendInfo":"{\\"deliveryTime\\":\\"2023-11-16T00:01:59Z\\",\\"deliveryDesc\\":\\"交货期我方计划为准XXX\\",\\"desc\\":\\"XXX标准XXX要求\\",\\"brand\\":\\"XXX品牌\\"}"}'),
  title?: string(name='Title', example='XX标题'),
}

model CreateSourcingProjectResponseBody = {
  code?: string(name='code', example='00000'),
  data?: string(name='data', example='13161242****5383'),
  message?: string(name='message', example='success'),
  requestId?: string(name='requestId', example='539E5C68-D8B5-57EC-9****8AFD9E0'),
  success?: boolean(name='success'),
}

model CreateSourcingProjectResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: CreateSourcingProjectResponseBody(name='body'),
}

async function createSourcingProjectWithOptions(tmpReq: CreateSourcingProjectRequest, headers: map[string]string, runtime: Util.RuntimeOptions): CreateSourcingProjectResponse {
  Util.validateModel(tmpReq);
  var request = new CreateSourcingProjectShrinkRequest{};
  OpenApiUtil.convert(tmpReq, request);
  if (!Util.isUnset(tmpReq.address)) {
    request.addressShrink = OpenApiUtil.arrayToStringWithSpecifiedStyle(tmpReq.address, 'Address', 'json');
  }
  if (!Util.isUnset(tmpReq.company)) {
    request.companyShrink = OpenApiUtil.arrayToStringWithSpecifiedStyle(tmpReq.company, 'Company', 'json');
  }
  if (!Util.isUnset(tmpReq.contact)) {
    request.contactShrink = OpenApiUtil.arrayToStringWithSpecifiedStyle(tmpReq.contact, 'Contact', 'json');
  }
  if (!Util.isUnset(tmpReq.extendInfo)) {
    request.extendInfoShrink = OpenApiUtil.arrayToStringWithSpecifiedStyle(tmpReq.extendInfo, 'ExtendInfo', 'json');
  }
  if (!Util.isUnset(tmpReq.subjects)) {
    request.subjectsShrink = OpenApiUtil.arrayToStringWithSpecifiedStyle(tmpReq.subjects, 'Subjects', 'json');
  }
  var query : map[string]any = {};
  if (!Util.isUnset(request.addressShrink)) {
    query['Address'] = request.addressShrink;
  }
  if (!Util.isUnset(request.bizId)) {
    query['BizId'] = request.bizId;
  }
  if (!Util.isUnset(request.bizNo)) {
    query['BizNo'] = request.bizNo;
  }
  if (!Util.isUnset(request.bizType)) {
    query['BizType'] = request.bizType;
  }
  if (!Util.isUnset(request.companyShrink)) {
    query['Company'] = request.companyShrink;
  }
  if (!Util.isUnset(request.contactShrink)) {
    query['Contact'] = request.contactShrink;
  }
  if (!Util.isUnset(request.createTime)) {
    query['CreateTime'] = request.createTime;
  }
  if (!Util.isUnset(request.expireTime)) {
    query['ExpireTime'] = request.expireTime;
  }
  if (!Util.isUnset(request.extendInfoShrink)) {
    query['ExtendInfo'] = request.extendInfoShrink;
  }
  if (!Util.isUnset(request.sourceUrl)) {
    query['SourceUrl'] = request.sourceUrl;
  }
  if (!Util.isUnset(request.subBizType)) {
    query['SubBizType'] = request.subBizType;
  }
  if (!Util.isUnset(request.subjectsShrink)) {
    query['Subjects'] = request.subjectsShrink;
  }
  if (!Util.isUnset(request.title)) {
    query['Title'] = request.title;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'CreateSourcingProject',
    version = '2024-01-04',
    protocol = 'HTTPS',
    pathname = `/srm/lite/sourcing/create`,
    method = 'POST',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function createSourcingProject(request: CreateSourcingProjectRequest): CreateSourcingProjectResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return createSourcingProjectWithOptions(request, headers, runtime);
}

model UpdateSourcingProjectRequest {
  bizId?: string(name='BizId', example='XXXIDXXX'),
  status?: string(name='Status', example='invalid'),
  updateTime?: string(name='UpdateTime', example='2023-12-08T00:01:59Z'),
}

model UpdateSourcingProjectResponseBody = {
  code?: string(name='code', example='00000'),
  data?: string(name='data', example='13161242****5383'),
  message?: string(name='message', example='success'),
  requestId?: string(name='requestId', example='539E5C68-D8B5-57EC-9****8AFD9E0'),
  success?: boolean(name='success'),
}

model UpdateSourcingProjectResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: UpdateSourcingProjectResponseBody(name='body'),
}

async function updateSourcingProjectWithOptions(request: UpdateSourcingProjectRequest, headers: map[string]string, runtime: Util.RuntimeOptions): UpdateSourcingProjectResponse {
  Util.validateModel(request);
  var query : map[string]any = {};
  if (!Util.isUnset(request.bizId)) {
    query['BizId'] = request.bizId;
  }
  if (!Util.isUnset(request.status)) {
    query['Status'] = request.status;
  }
  if (!Util.isUnset(request.updateTime)) {
    query['UpdateTime'] = request.updateTime;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'UpdateSourcingProject',
    version = '2024-01-04',
    protocol = 'HTTPS',
    pathname = `/srm/lite/sourcing/update`,
    method = 'POST',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function updateSourcingProject(request: UpdateSourcingProjectRequest): UpdateSourcingProjectResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return updateSourcingProjectWithOptions(request, headers, runtime);
}

